package com.sesxh.project.knowledge.router;

import java.util.Map;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.sesxh.frame.core.data.DataSet;
import com.sesxh.frame.web.controller.BaseController;
import com.sesxh.project.knowledge.biz.model.Knowledge;
import com.sesxh.project.knowledge.biz.service.IKnowledgeService;
@Controller 
@RequestMapping("/knowledge")
public class KnowledgeController implements BaseController {

	
	@Autowired
	private IKnowledgeService knowledgeService;
	
	
	
	 @RequestMapping(value="/search", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	 public  @ResponseBody Object search(Knowledge knowledge){
			knowledgeService.createKnowledge(knowledge);
	    return ajaxDoneSuccess("数据操作成功 ");
	}
	  
	  
    @RequestMapping(value="/loadKnowledgeDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadKnowledgeDataSet(@RequestParam Map<String,Object> params){
	    DataSet dataSet=  knowledgeService.loadKnowledgeDataSet(params);
	    return ajaxQuery("dataSet", dataSet);
    }
	
    @RequestMapping(value="/createKnowledge", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object createKnowledge(Knowledge knowledge){
		knowledgeService.createKnowledge(knowledge);
    	return ajaxDoneSuccess("数据操作成功 ");
    }
	
    @RequestMapping(value="/loadKnowledge", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadKnowledge(Long id){
		Optional<Knowledge> ops = knowledgeService.loadKnowledgeById(id);
		return ajaxQuery("knowledge",ops);
    }
	
    @RequestMapping(value="/updateKnowledge", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object updateKnowledge(Knowledge knowledge){
		knowledgeService.updateKnowledge(knowledge);
		return ajaxDoneSuccess("数据操作成功 ");
    }
	
    @RequestMapping(value="/deleteKnowledge", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object deleteKnowledge(Long id){
		knowledgeService.deleteKnowledge(id);
		return ajaxDoneSuccess("数据操作成功 ");
    }

}